//
//  PersonalCell.m
//  TheRoadAD
//
//  Created by baixue on 16/8/15.
//  Copyright © 2016年 baixue. All rights reserved.
//

#import "PersonalCell.h"
#import "LikeHeadImgView.h"

@implementation PersonalCell
{
    PhotosView *_photosView;
    LikeHeadImgView *_likeHeaImgView;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    PhotosView *photosView = [[PhotosView alloc] initWithMaxItemsCount:9];
    _photosView = photosView;
    [self.contentView addSubview:photosView];
    LikeHeadImgView *likeHeaImgView = [[LikeHeadImgView alloc] init];
    _likeHeaImgView = likeHeaImgView;
    [self.contentView addSubview:likeHeaImgView];
    
    
    self.userName.font = [UIFont fontWithName:@"qingyuan" size:14.0f];
    self.timer.font = [UIFont fontWithName:@"qingyuan" size:10.0f];
    self.content.font = [UIFont fontWithName:@"qingyuan" size:14.0f];
    
    //适配
    self.headImg.sd_layout
    .leftSpaceToView(self.contentView, 10)
    .topSpaceToView(self.contentView, 10)
    .widthIs(40 * Screen_Height/736)
    .heightEqualToWidth();
    
    self.userName.sd_layout
    .leftSpaceToView(self.headImg,10)
    .topSpaceToView(self.contentView,10)
    .rightSpaceToView(self.contentView,10).heightIs(20);
    
    self.timer.sd_layout
    .leftEqualToView(self.userName)
    .topSpaceToView(self.userName,2)
    .rightEqualToView(self.userName).heightIs(15);
    
    self.content.sd_layout
    .leftEqualToView(self.timer)
    .topSpaceToView(self.timer,10)
    .rightSpaceToView(self.contentView,10)
    .autoHeightRatio(0);
    
    
    //头像设置圆角
    self.headImg.layer.cornerRadius = 20 * Screen_Height/736;
    self.headImg.layer.masksToBounds = YES;
    
    
    _photosView.sd_layout
    .leftEqualToView(self.content)
    .rightEqualToView(self.content)
    .topSpaceToView(self.content,2);
    
    
    _likeHeaImgView.sd_layout.leftEqualToView(self.userName).rightSpaceToView(self.contentView,10).topSpaceToView(_photosView,10).heightIs(30);
//    _likeHeaImg.backgroundColor = [UIColor redColor];
    
}

-(void)setModel:(UserModel *)model{
    
    _headImg.image = [UIImage imageNamed:model.headImage];
    
    _userName.text = model.userName;
    _timer.text = model.timer;
    _content.text = model.content;

    UIView *footerView = _content;
    _likeHeaImgView.headImg = model.likeImage;//fans数组
    _photosView.photoNamesArray = model.imageArray;//图片数组
    NSMutableArray *com = [NSMutableArray arrayWithObjects:_headImg,_userName,_timer,_content,_likeHeaImgView, nil];
    
   
    
    if (model.imageArray.count > 0) {
        _photosView.hidden = NO;
        footerView = _photosView;
        [com addObject:_photosView];
        _likeHeaImgView.sd_layout
        .leftEqualToView(self.userName)
        .topSpaceToView(_photosView,10)
        .rightSpaceToView(self.contentView,10)
        .heightIs(30);
    }else{
        _photosView.hidden = YES;
       
        
        _likeHeaImgView.sd_layout
        .leftEqualToView(self.userName)
        .topSpaceToView(_content,10)
        .rightSpaceToView(self.contentView,10)
        .heightIs(30);
    }
    
    [self setupAutoHeightWithBottomViewsArray:com bottomMargin:10];
    
}

@end
